<?php

include_once dirname(dirname(__FILE__)) . '/include/common.php';
$customer_order_id = isset($_POST["customer_order_id"]) ? intval($_POST["customer_order_id"]) : 0;
$core = new core();
if ($customer_order_id == "" || $customer_order_id <= 0) {
    echo json_encode(array('type' => 1, 'msg' => "Có lỗi xảy ra, vui lòng thử lại!"));
    die;
} else {
    $customer_order = $core->getCustomerOrderDetailById($customer_order_id);
    if ($customer_order) {
        $count = 0;
        $list_product_id = array();
        $list_product_number = array();
        $list_product_size = array();
        $list_product_color = array();
        $list_product_price = array();
        $list_product_description = array();
        $list_product_code = array();
        $list_product_image = array();
        $list_zcod_id = array();
        $list_product_status = array();
        $list_customer_order_date = array();
        $list_online_date = array();
        $list_store_date = array();
        $list_saled_date = array();
        $list_received_date = array();
        $list_price_pt = array();
        $list_price_at = array();
        foreach ($customer_order as $order_detail) {
            if ($count == 0) {
                $customer_phone = $order_detail->phone;
                $customer_fb_name = stripslashes($order_detail->facebook_name);
                $customer_name = stripslashes($order_detail->name);
                $customer_email = stripslashes($order_detail->email);
                $customer_wholesale = $order_detail->wholesale;
                $customer_address = stripslashes($order_detail->address);
                $customer_province = $order_detail->province;
                $customer_id = $order_detail->customer_id;
                $order_description = stripslashes($order_detail->order_description);
                $type_calculate_payment = $order_detail->type_calculate_payment;
                $service_percent = $order_detail->service_percent;
                $fee_per_kg = $order_detail->fee_per_kg;
                $weight = $order_detail->weight;
                $exchange_money = $order_detail->exchange/1000;
                $count++;
            }
            $color_photo_name = $order_detail->product_color . "_" . $order_detail->product_code . "_" . $order_detail->manufacture;
            $color_photo_name = $core->convert_string_friendly($color_photo_name) . ".jpg";
            $path_color_photo = dirname(dirname(__FILE__)) . DS . "photo" . DS . "extra_photo" . DS . "thumb_extra_photo" . DS . $color_photo_name;
            if (file_exists($path_color_photo)) {               
                $src_photo_thumb = 'photo/extra_photo/thumb_extra_photo/' . $color_photo_name;
            } else {
                $src_photo_thumb = 'photo/thumb_photo/200_' . $order_detail->main_photo;
            }
            $list_product_id[] = $order_detail->product_id;
            $list_product_number[] = $order_detail->order_product_num;
            $list_product_size[] = stripslashes($order_detail->product_size);
            $list_product_color[] = stripslashes($order_detail->product_color);

            $list_product_description[] = stripslashes($order_detail->description);
            $list_product_code[] = $order_detail->product_code;
            $list_product_image[] = $src_photo_thumb;
            $list_zcod_id[] = $order_detail->id;
            $list_product_status[] = $order_detail->order_status;
            $list_customer_order_date[] = $order_detail->customer_order_date;
            $list_online_date[] = $order_detail->online_date;
            $list_store_date[] = $order_detail->store_date;
            $list_saled_date[] = $order_detail->saled_date;
            $list_received_date[] = $order_detail->received_date;

            if($order_detail->order_status==6){
                $list_product_price[] = 0;
                $list_price_pt[] = 0;
                $list_price_at[] = 0;
            }else{
                $list_product_price[] = number_format($order_detail->product_price / 1000);
                $list_price_pt[] = number_format($order_detail->store_price,2);
                $list_price_at[] = number_format($order_detail->stamp_price,2);
            }
        }

        echo json_encode(array('type' => 0, 'customer_order_id' => $customer_order_id,
            'phone' => $customer_phone, "customer_fb_name" => $customer_fb_name,
            'customer_name' => $customer_name, "customer_email" => $customer_email,
            'customer_address' => $customer_address, 'customer_id' => $customer_id,
            'customer_province' => $customer_province, 'customer_wholesale' => $customer_wholesale, 'order_description' => $order_description,
            'type_calculate_payment'=>$type_calculate_payment,'service_percent'=>$service_percent,
            'fee_per_kg'=>$fee_per_kg, 'weight'=>$weight,'exchange_money'=>$exchange_money,
            'list_product_id' => $list_product_id, 'list_product_number' => $list_product_number,
            'list_product_size' => $list_product_size, 'list_product_color' => $list_product_color,
            'list_product_price' => $list_product_price, 'list_product_description' => $list_product_description,
            'list_product_code' => $list_product_code, 'list_product_image' => $list_product_image,
            'list_zcod_id' => $list_zcod_id, 'list_product_status' => $list_product_status,
            'list_customer_order_date' => $list_customer_order_date, 'list_online_date' => $list_online_date,
            'list_store_date' => $list_store_date, 'list_saled_date' => $list_saled_date,
            'list_received_date' => $list_received_date,
            'list_price_pt' => $list_price_pt,'list_price_at' => $list_price_at));

        die;
    } else {
        echo json_encode(array('type' => 1, 'msg' => "Có lỗi xảy ra, vui lòng thử lại!"));
        die;
    }
}
?>